import 'package:flutter/material.dart';
import 'package:mi_mang_flutter/res/styles.dart';
import 'package:mi_mang_flutter/utils/image_utils.dart';

/// 异常页
class WidgetError extends StatelessWidget {
  const WidgetError({
    Key? key,
    required this.onPressed,
    this.errMsg,
    this.errTips,
  }) : super(key: key);

  /// 重试点击事件
  final VoidCallback onPressed;

  /// 异常信息
  final String? errMsg;

  /// 异常提醒建议
  final String? errTips;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //创建透明层
      resizeToAvoidBottomInset: false,
      backgroundColor: Colors.transparent,
      body: Container(
        height: double.infinity,
        width: double.infinity,
        padding: EdgeInsets.all(15.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Expanded(
              child: Gaps.empty,
              flex: 2,
            ),
            SizedBox(
              width: 189.0,
              height: 170.0,
              child: loadImage('public/error'),
            ),
            Gaps.vGap10,
            Text(
              '系统异常',
              style: TextStyle(fontSize: 12.0, color: Colors.grey[600]),
            ),
            Text(
              errMsg ?? '',
              style: TextStyle(fontSize: 12.0, color: Colors.grey[600]),
            ),
            errTips != null && errTips!.isNotEmpty
                ? Text(
                    errTips ?? '系统发生了异常,请稍后重试',
                    style: TextStyle(fontSize: 12.0, color: Colors.grey[600]),
                  )
                : Gaps.empty,
            Gaps.vGap8,
            MaterialButton(
              height: 30.0,
              child: Text(
                '再试一次',
                style: TextStyle(color: Colors.white, fontSize: 12.0),
              ),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(15),
              ),
              onPressed: onPressed,
            ),
            Expanded(
              child: Gaps.empty,
              flex: 3,
            ),
          ],
        ),
      ),
    );
  }
}
